package com.zkw.group.controller;

import com.alibaba.fastjson.JSON;
import com.zkw.group.entity.*;
import com.zkw.group.service.CourseIndicatorSupportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@Api(description = "管理课程对应能力指标支撑度信息")
@CrossOrigin
@RestController
@RequestMapping("/CourseIndicatorSupports")
public class CourseIndicatorSupportController {

    @Autowired
    private CourseIndicatorSupportService courseIndicatorSupportService;

    @ApiOperation(value = "分页查询课程对应能力指标支撑度信息")
    @GetMapping("/AllCourseIndicatorSupport")
    public String getAllCourseIndicatorSupportList(QueryInfo queryInfo) {
        int numbers = courseIndicatorSupportService.getCourseIndicatorSupportCounts(queryInfo.getQuery(),queryInfo.getRole());
        int pageStart = (queryInfo.getPageNum()-1)*queryInfo.getPageSize();
        List<CourseIndicatorSupport> courseIndicatorSupports = courseIndicatorSupportService.getAllCourseIndicatorSupportList(queryInfo.getQuery(),queryInfo.getRole(),pageStart,queryInfo.getPageSize());
        HashMap<String, Object> res = new HashMap<>();
        res.put("numbers",numbers);
        res.put("data",courseIndicatorSupports);
        return JSON.toJSONString(res);
    }

    @ApiOperation(value = "添加课程对应能力指标支撑度信息")
    @PostMapping("/CourseIndicatorSupport")
    public String addCourseIndicatorSupport(@RequestBody CourseIndicatorSupport courseIndicatorSupport) {
        int result =  courseIndicatorSupportService.addCourseIndicatorSupport(courseIndicatorSupport);
        if (result >= 1) {
            return "success";
        } else {
            return "error";
        }
    }

    @ApiOperation(value = "删除指定课程对应能力指标支撑度信息")
    @DeleteMapping("/CourseIndicatorSupport")
    public String deleteCourseIndicatorSupport(String sid) {
        int result = courseIndicatorSupportService.deleteCourseIndicatorSupport(sid);
        if (result >= 1) {
            return "success";
        } else {
            return "error";
        }
    }

    @ApiOperation(value = "获取每个二级指标各个支撑度数目统计")
    @GetMapping("/CourseIndicatorSupportCountsList")
    public String getCourseIndicatorSupportCountsList(QueryInfo queryInfo){
        int numbers = courseIndicatorSupportService.getIndicatorSupportCounts(queryInfo.getQuery());
        int pageStart = (queryInfo.getPageNum()-1)*queryInfo.getPageSize();
        List<IndicatorSupport> indicatorSupports = courseIndicatorSupportService.getIndicatorSupportList(queryInfo.getQuery(),pageStart,queryInfo.getPageSize());
        HashMap<String, Object> res = new HashMap<>();
        res.put("numbers",numbers);
        res.put("data",indicatorSupports);
        return JSON.toJSONString(res);
    }

    @ApiOperation(value = "获取一级指标名称以及编号列表")
    @GetMapping("/IndicatorOneNameList")
    public String getIndicatorOneNameList(){
        List<ProfesIndicatorOne> profesIndicatorOnes = courseIndicatorSupportService.getIndicatorOneNameList();
        HashMap<String, Object> res = new HashMap<>();
        res.put("data",profesIndicatorOnes);
        return JSON.toJSONString(res);
    }

    @ApiOperation(value = "获取一级指标下的二级指标名称以及编号列表")
    @GetMapping("/IndicatorTwoNameList")
    public String getIndicatorTwoNameList(String findicname){
        List<ProfesIndicatorTwo> profesIndicatorTwos = courseIndicatorSupportService.getIndicatorTwoNameList(findicname);
        HashMap<String, Object> res = new HashMap<>();
        res.put("data",profesIndicatorTwos);
        return JSON.toJSONString(res);
    }

    @ApiOperation(value = "获取每个课程各个支撑度数目统计")
    @GetMapping("/CourseSupportCountsList")
    public String getCourseSupportCountsList(QueryInfo queryInfo){
        int numbers = courseIndicatorSupportService.getCourseSupportCounts(queryInfo.getQuery());
        int pageStart = (queryInfo.getPageNum()-1)*queryInfo.getPageSize();
        List<CourseSupport> courseSupports = courseIndicatorSupportService.getCourseSupportList(queryInfo.getQuery(),pageStart,queryInfo.getPageSize());
        HashMap<String, Object> res = new HashMap<>();
        res.put("numbers",numbers);
        res.put("data",courseSupports);
        return JSON.toJSONString(res);
    }
}
